import { routerRedux } from 'dva/router';
import { message } from 'antd';
import { isResponerCode } from '../utils/utils';
import {
  fetchApply,
  detailsApply,
  saveAssets,
  getProList,
  saveAbility,
  fetchApplyOperateDetail,
  getSignContract,
  businessPerform,
  getReleaseAmt,
  commitReleaseAmt,
  getPickCar,
  commitPickCar,
  getApplyProductList,
  saveCustomerInfo,
  saveBusiness,
  businessAllCommit,
  opposeCheat,
  identityAuthentic,
  getCreateApplyDetails,
  getCarBrandList,
  getCarSystemList,
  getCarModelList,
  deleteFile,
  createApply,
  updateStartApply,
  approvalProgress,
  commitSignContract,
  getBankApprovalList,
  deleteRelation,
  getPrePayList,
  prepayExport,
  submitData,
} from '../services/api';


const CUSTOMER_STATE_SELF = 1;
const CUSTOMER_STATE_PAYER = 2;
const CUSTOMER_STATE_GUARANTOR = 3;

export default {
  namespace: 'apply',

  state: {
    isLoaded: false,
    customers: [{
      name: '',
      description: '',
      key: `0`,
      id: `0`,
      documentList: [],
      thridVerifyList: [],
      state: 1,
    }],
    applyList: [],
    applyLoading: false,
    applyResult: {},
    applyCustomerResult: {},
    identityAuthenticList: null,
    opposeCheatList: null,
    applyPage: {},
    applyListDetails: null,
    applyDetailsLoading: false,
    applyProList: [],
    operateDetail: {},
    signContractDetails: null,
    releaseAmtDetails: null,
    pickCarDetails: null,
    applyProductList: null,
    applyBusinessLoading: false,
    applyPickCarLoading: false,
    saveBusinessLoading: false,
    applyReleaseAmtLoading: false,
    opposeCheatLoading: false,
    applyDetails: null,
    applyBranchCarList: null,
    applySystemCarList: null,
    applyModelCarList: null,
    identityAuthentic: null,
    applyApprovalProgress: null,
    applyBranchList: null,
    loadThirdPartyDataLoading: false,
    prePayList: null,
    prePayPage: null,
    
  },

  effects: {
    //业务列表
    *fetchApply({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(fetchApply, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          applyList: response.data.list,
          applyPage: response.data.page,
        },
      });
      if (callback) callback();
    },

    //反欺诈查询
    *opposeCheat({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          loadThirdPartyDataLoading: true,
        },
      });
      const response = yield call(opposeCheat, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'loadThirdPartyData',
          payload: false
        });
        yield put({
          type: 'save',
          payload: {
            loadThirdPartyDataLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          loadThirdPartyDataLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          opposeCheatList: response.data,
          applyResult: response.result
        },
      });
      if (callback) callback();
    },

    //个人身份认证
    *getIdentityAuthentic({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyIdentityLoading: true,
        },
      });
      const response = yield call(identityAuthentic, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'loadThirdPartyData',
          payload: false
        });
        yield put({
          type: 'save',
          payload: {
            applyIdentityLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyIdentityLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          identityAuthenticList: response.data,
          applyResult: response.result
        },
      });
      if (callback) callback();
    },
    //业务详情
    *detailsApply({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(detailsApply, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          applyListDetails: response.data,
        },
      });
      if (callback) callback();
    },


    //业务详情的 ---资产信息提交
    *saveAssets({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(saveAssets, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });

      if (callback) callback();
    },
    
    //业务补导入
    *submitData({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(submitData, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });

      if (callback) callback();
    },
    //业务详情的 ---
    *saveAbility({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(saveAbility, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });
      if (callback) callback();
    },

    //业务受理  详情
    *fetchApplyOperateDetail({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(fetchApplyOperateDetail, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          operateDetail: response.data,
        },
      });
      if (callback) callback();
    },

    //业务受理  开始执行
    *businessPerform({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(businessPerform, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });
      if (callback) callback();
    },

    //签约管理
    *getSignContract({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(getSignContract, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          signContractDetails: response.data,
        },
      });
      if (callback) callback();
    },

    //放款管理
    *getReleaseAmt({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(getReleaseAmt, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          releaseAmtDetails: response.data,
        },
      });
      if (callback) callback();
    },

    //提交放款
    *commitReleaseAmt({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyReleaseAmtLoading: true,
        },
      });
      const response = yield call(commitReleaseAmt, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyReleaseAmtLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyReleaseAmtLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });
      if (callback) callback();
    },

    //提车信息
    *getPickCar({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(getPickCar, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          pickCarDetails: response.data,
        },
      });
      if (callback) callback();
    },

    //提车信息
    *commitPickCar({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: true,
        },
      });
      const response = yield call(commitPickCar, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyPickCarLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });
      if (callback) callback();
    },

    //业务详情--客户详情保存
    *saveCustomerInfo({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: true,
        },
      });
      const response = yield call(saveCustomerInfo, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyPickCarLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });
      if (callback) callback();
    },

    //在业务中获取经销商列表
    *getProList({ payload }, { call, put }) {
      const response = yield call(getProList, payload);
      if (!isResponerCode(response)) {
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyProList: response.data,
          applyPage: response.data,
        },
      });
    },

    //业务详情--业务信息保存
    *saveBusiness({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          saveBusinessLoading: true,
        },
      });
      const response = yield call(saveBusiness, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            saveBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          saveBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });
      if (callback) callback();
    },

    //业务详情整体提交
    *businessAllCommit({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: true,
        },
      });
      const response = yield call(businessAllCommit, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });
      if (callback) callback();
    },

    //业务申请详情获取
    *getCreateApplyDetails({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: true,
        },
      });
      const response = yield call(getCreateApplyDetails, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          applyDetails: response.data,
          customers: response.data.customers,
        },
      });
      yield put({
        type: 'toogleLoadStatus',
        payload: true,
      });
      if (callback) callback();
    },

    //获取车品牌
    *getCarBrandList({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: true,
        },
      });
      const response = yield call(getCarBrandList, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          applyBranchCarList: response.data,
        },
      });
      if (callback) callback();
    },

    //获取车系
    *getCarSystemList({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: true,
        },
      });
      const response = yield call(getCarSystemList, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          applySystemCarList: response.data,
        },
      });
      if (callback) callback();
    },
    //获取车型
    *getCarModelList({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: true,
        },
      });
      const response = yield call(getCarModelList, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          applyModelCarList: response.data,
        },
      });
      if (callback) callback();
    },

    //删除附件
    *deleteFile({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: true,
        },
      });
      const response = yield call(deleteFile, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result
        },
      });
      if (callback) callback();
    },

    //业务申请
    *createApply({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: true,
        },
      });
      const response = yield call(createApply, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result
        },
      });
      if (callback) callback();
    },

    //业务申请 驳回后修改
    *updateStartApply({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: true,
        },
      });
      const response = yield call(updateStartApply, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyBusinessLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyBusinessLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result
        },
      });
      if (callback) callback();
    },

    //查看业务流程进度
    *approvalProgress({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: true,
        },
      });
      const response = yield call(approvalProgress, payload);
      if (response.result && response.result.code == 200) {
        yield put({
          type: 'save',
          payload: {
            applyPickCarLoading: false,
          },
        });
        yield put({
          type: 'save',
          payload: {
            applyApprovalProgress: response.data,
          },
        });
      } else {
        yield put({
          type: 'save',
          payload: {
            applyPickCarLoading: false,
          },
        });
        message.error("服务器返回为空")
      }

      if (callback) callback();
    },

    //查看业务流程进度
    *commitSignContract({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: true,
        },
      });
      const response = yield call(commitSignContract, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyPickCarLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result
        },
      });
      if (callback) callback();
    },

    //获取上报银行后的返回结果意见
    *getBankApprovalList({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: true,
        },
      });
      const response = yield call(getBankApprovalList, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyPickCarLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          applyBranchList: response.data,
        },
      });
      if (callback) callback();
    },

    //业务中删除关系人
    *deleteRelation({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: true,
        },
      });
      const response = yield call(deleteRelation, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyPickCarLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyPickCarLoading: false,
        },
      });
      yield put({
        type: 'save',
        payload: {
          data: response.data,
          applyResult: response.result,
        },
      });
      if (callback) callback();
    },

    //业务预付费列表
    *getPrePayList({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(getPrePayList, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          prePayList: response.data.list,
          prePayPage: response.data.page,
          applyResult: response.result,
          applyLoading: false,
        },
      });
      if (callback) callback();
    },

     //业务预付费列表导出
     *prepayExport({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          applyLoading: true,
        },
      });
      const response = yield call(prepayExport, payload);
      if (!isResponerCode(response)) {
        yield put({
          type: 'save',
          payload: {
            applyLoading: false,
          },
        });
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyResult: response.result,
          applyLoading: false,
        },
      });
      if (callback) callback();
    },

    *getProductList({ payload, callback }, { call, put }) {
      const response = yield call(getApplyProductList, payload);
      if (!isResponerCode(response)) {
        return false
      }
      yield put({
        type: 'save',
        payload: {
          applyProductList: response.data,
        },
      });
    },

    *addCustomer({ payload, callback }, { select, call, put }) {
      const currentCustomers = yield select(state => state.apply.customers);
      const customers = [...currentCustomers, payload];
      yield put({
        type: 'save',
        payload: {
          customers,
        },
      });
      if (callback) callback();
    },

    *removeCustomer({ payload, callback }, { select, call, put }) {
      const currentCustomers = yield select(state => state.apply.customers);
      const customers = currentCustomers.filter(item => item.id != payload.id);//返回true则保留当前项，反之移除当前项
      // const customers = [...currentCustomers, payload];

      yield put({
        type: 'save',
        payload: {
          customers,
        },
      });
      if (callback) callback();
    },

    *changeMainApplyer({ payload, callback }, { call, put, select }) {
      const oldCustomers = yield select(state => state.apply.customers);
      const filtered = oldCustomers.filter((item, index) => index > 0);
      //const customers = [OverflowEvent
      const customer = { ...oldCustomers[0], ...payload.customer };
      const customers = [customer];

      yield put({
        type: 'save',
        payload: {
          customers: customers,
        },
      });
    },


    *changeGuarantor({ payload, callback }, { call, put, select }) {
      const customers = yield select(state => state.apply.customers);
      const guarantorList = customers && customers.filter(item => item.state == CUSTOMER_STATE_GUARANTOR);
      const payerList = customers && customers.filter(item => item.state == CUSTOMER_STATE_PAYER);
      const guarantor = { ...guarantorList[payload.index], ...payload.guarantor };
      const filteredGreaterThanMe = guarantorList.filter((item, index) => index > payload.index);
      const filteredLessThanMe = guarantorList.filter((item, index) => index < payload.index);

      const newCustomers = [
        customers[0],
        ...filteredLessThanMe,
        guarantor,
        ...filteredGreaterThanMe,
        ...payerList,
      ];
      yield put({
        type: 'save',
        payload: {
          customers: newCustomers,
        },
      });
    },

    *changePayer({ payload, callback }, { call, put, select }) {
      const customers = yield select(state => state.apply.customers);
      const guarantorList = customers && customers.filter(item => item.state == CUSTOMER_STATE_GUARANTOR);
      const payerList = customers && customers.filter(item => item.state == CUSTOMER_STATE_PAYER);
      const payer = { ...payerList[payload.index], ...payload.payer };
      const filteredGreaterThanMe = payerList.filter((item, index) => index > payload.index);
      const filteredLessThanMe = payerList.filter((item, index) => index < payload.index);

      const newCustomers = [
        customers[0],
        ...guarantorList,
        ...filteredLessThanMe,
        payer,
        ...filteredGreaterThanMe,
      ];
      yield put({
        type: 'save',
        payload: {
          customers: newCustomers,
        },
      });
    },

    *changeImageForCustomer({ payload, callback }, { call, put, select }) {
      const { customerInfo, fieldName, imageList, type } = payload;
        // console.log(" customerInfo", customerInfo)
      const customers = yield select(state => state.apply.customers);
        // console.log(" state.apply", customers)
      const newCustomers = customers.map((item, index) => {
        // console.log("customers", customers)
        if (item.id == customerInfo.id) {
          if (!type) {
            if (imageList.length > 0 && imageList[0].status == 'done') {
              item[fieldName] = imageList[0].key;
              return item;
            } else {
              return item;
            }
          } else {
            item[fieldName] = '';
            return item;
          }

        } else {
          return item;
        }
      });
      yield put({
        type: 'save',
        payload: {
          customers: newCustomers,
        },
      });
    },

  },

  reducers: {
    saveStepFormData(state, { payload }) {
      return {
        ...state,
        step: {
          ...state.step,
          ...payload,
        },
      };
    },

    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },

    toogleLoadStatus(state, { payload }) {
      return {
        ...state,
        isLoaded: payload,
      };
    },

    loadThirdPartyData(state, { payload }) {
      return {
        ...state,
        loadThirdPartyDataLoading: payload,
      };
    },

    clearPage(state) {
      return {
        customers: [{
          name: '',
          description: '',
          key: `0`,
          id: `0`,
          documentList: [],
          thridVerifyList: [],
          state: 1,
        }],
        applyList: [],
        applyLoading: false,
        applyResult: null,
        identityAuthenticList: null,
        opposeCheatList: null,
        applyPage: {},
        applyListDetails: null,
        applyDetailsLoading: false,
        applyProList: [],
        operateDetail: {},
        signContractDetails: null,
        releaseAmtDetails: null,
        pickCarDetails: null,
        applyProductList: null,
        applyBusinessLoading: false,
        applyPickCarLoading: false,
        saveBusinessLoading: false,
        applyReleaseAmtLoading: false,
        applyDetails: null,
        applyBranchCarList: null,
        applySystemCarList: null,
        applyModelCarList: null,
        opposeCheatLoading: false,
        applyIdentityLoading: false,
        loadThirdPartyDataLoading: false,
      }
    },
  },
};
